home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11ys.zip / UUCP / UUSUB.C < prev    next >
C/C++ Source or Header  |  1993-04-10  |  10KB  |  304 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    u u s u b . c                                                   */
  3. /*                                                                    */
  4. /*    Report summary of UUPC activity                                 */
  5. /*                                                                    */
  6. /*    Copyright (C) 1991-1993, Andrew H. Derbyshire                   */
  7. /*--------------------------------------------------------------------*/
  8.  
  9. /*
  10.  *    $Id: UUSUB.C 1.3 1993/04/11 00:35:46 ahd Exp $
  11.  *
  12.  *    $Log: UUSUB.C $
  13.  * Revision 1.3  1993/04/11  00:35:46  ahd
  14.  * Global edits for year, TEXT, etc.
  15.  *
  16.  * Revision 1.2  1992/11/19  03:03:24  ahd
  17.  * drop rcsid
  18.  *
  19.  */
  20.  
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <time.h>
  26.  
  27. #include "lib.h"
  28. #include "hostable.h"
  29. #include "dater.h"
  30. #include "hostrset.h"
  31. #include "hostatus.h"
  32. #include "getopt.h"
  33. #include "security.h"
  34. #include "timestmp.h"
  35.  
  36. /*--------------------------------------------------------------------*/
  37. /*                            Local macros                            */
  38. /*--------------------------------------------------------------------*/
  39.  
  40. #define line( a, b, c, d, e, f, g, h, i, j ) \
  41.       printf("%-8.8s %-6.6s %-11.11s %-11.11s %5.5s %5.5s %5.5s %5.5s %5.5s %5.5s\n" ,\
  42.       a, b, c, d, e, f, g, h, i ,j )
  43.  
  44. /*--------------------------------------------------------------------*/
  45. /*                        Internal prototypes                         */
  46. /*--------------------------------------------------------------------*/
  47.  
  48. static void showstats( const char *name );
  49. static void showhost( struct HostTable *host);
  50. static char *when( time_t t );
  51. static char *status( hostatus current_status );
  52. static char *format( long l);
  53.  
  54. /*--------------------------------------------------------------------*/
  55. /*                          Global variables                          */
  56. /*--------------------------------------------------------------------*/
  57.  
  58. static char output[10 * 12];
  59. static size_t column ;
  60.  
  61. currentfile();
  62.  
  63. /*--------------------------------------------------------------------*/
  64. /*    u s a g e                                                       */
  65. /*                                                                    */
  66. /*    Report flags used by program                                    */
  67. /*--------------------------------------------------------------------*/
  68.  
  69. static         void    usage(void)
  70. {
  71.       fprintf(stderr, "Usage: uusub\t[-c] [-s <nodename>] [-x debug]\n");
  72. }
  73.  
  74. /*--------------------------------------------------------------------*/
  75. /*                            main program                            */
  76. /*--------------------------------------------------------------------*/
  77.  
  78. #ifdef __TURBOC__
  79. #pragma argsused
  80. #endif
  81.  
  82. void main( int argc , char **argv)
  83. {
  84.  
  85.    int         option;
  86.    boolean clear_stats = FALSE;
  87.    char *name = nil(char);
  88.  
  89. /*--------------------------------------------------------------------*/
  90. /*               Announce ourselves to a waiting world                */
  91. /*--------------------------------------------------------------------*/
  92.  
  93.    debuglevel = 0;
  94.  
  95. #if defined(__CORE__)
  96.    copywrong = strdup(copyright);
  97.    checkref(copywrong);
  98. #endif
  99.    banner( argv );
  100.  
  101. /*--------------------------------------------------------------------*/
  102. /*       Load system configuration and then the UUPC host stats       */
  103. /*--------------------------------------------------------------------*/
  104.  
  105.    if (!configure( B_UUSTAT ))
  106.       panic();
  107.  
  108.    HostStatus();
  109.  
  110. /*--------------------------------------------------------------------*/
  111. /*                        Process option flags                        */
  112. /*--------------------------------------------------------------------*/
  113.  
  114.    while ((option = getopt(argc, argv, "cs:x:")) != EOF)  {
  115.       switch(option)  {
  116.          case 'c':               /* clear stats */
  117.             clear_stats = TRUE;
  118.             break;
  119.          case 's':               /* only named host */
  120.             name = optarg;
  121.             break;
  122.          case 'x':
  123.             debuglevel = atoi(optarg);
  124.             break;
  125.          default:
  126.             usage();
  127.             exit(1);
  128.             break;
  129.       }
  130.    }
  131.  
  132.    if (optind != argc)
  133.    {
  134.       puts("Extra parameter(s) at end.");
  135.       exit(4);
  136.    }
  137.  
  138.    if ( (name != NULL) && (checkreal( name ) == BADHOST) )
  139.        printf("Unknown host \"%s\"\n", name );
  140.    else if (clear_stats)
  141.    {
  142.        HostReset((const char *)name);
  143.        if ( name == NULL )
  144.          time( &start_stats );
  145.    }
  146.    else
  147.        showstats((const char *)name);
  148.  
  149. } /* main */
  150.  
  151.  
  152. /*--------------------------------------------------------------------*/
  153. /*    s h o w s t a t s                                               */
  154. /*                                                                    */
  155. /*    Display information on all hosts                                */
  156. /*--------------------------------------------------------------------*/
  157.  
  158. static void showstats( const char *name )
  159. {
  160.    struct HostTable *host;
  161.    boolean firsthost = TRUE;
  162.    static const char *dashes = "-----------";
  163.  
  164.    printf("Host information collected since %s\n",ctime( &start_stats ));
  165.  
  166.    line("Host","Host ",  "Date Last",  "Last Conn","Secs" , "Bytes", "Bytes",
  167.          "Files", "Files", "Total");
  168.    line("Name","Status ","Connected ","Attempt", "Conn",  "Sent",  "Recvd",
  169.         "Sent",  "Recvd", "Errs");
  170.    line(dashes,dashes,dashes,dashes,dashes,dashes,dashes,dashes,
  171.          dashes,dashes);
  172.  
  173.    if (name != NULL)
  174.       showhost ( checkreal(name) );
  175.    else
  176.       while  ((host = nexthost( firsthost )) != BADHOST)
  177.       {
  178.          firsthost = FALSE;
  179.          showhost ( host );
  180.       } /* while */
  181.  
  182. } /* showstats */
  183.  
  184. /*--------------------------------------------------------------------*/
  185. /*    s h o w h o s t                                                 */
  186. /*                                                                    */
  187. /*    Display information on a single host                            */
  188. /*--------------------------------------------------------------------*/
  189.  
  190. static void showhost( struct HostTable *host)
  191. {
  192.    column = 0;
  193.    checkref( host->hstats );
  194.    line( host->hostname,
  195.       status( host->hstatus ),
  196.       when( host->hstats->lconnect ),
  197.       when( host->hstats->ltime ),
  198.       format( host->hstats->connect ),
  199.       format( host->hstats->bsent ),
  200.       format( host->hstats->breceived ),
  201.       format( host->hstats->fsent ),
  202.       format( host->hstats->freceived ),
  203.       format( host->hstats->errors  ));
  204. } /* showhost */
  205.  
  206. /*--------------------------------------------------------------------*/
  207. /*                            Subroutines                             */
  208. /*--------------------------------------------------------------------*/
  209.  
  210. static char *when( time_t t )
  211. {
  212.    column += 13;
  213.    return dater( t, &output[column]);
  214. } /* when */
  215.  
  216. static char *format( long l)
  217. {
  218.    if (l == 0)
  219.       return "";
  220.  
  221.    column += 12;
  222.    if ( l <= 99999)
  223.       sprintf( &output[ column ], "%ld", l);
  224.    else if ( (l/1000) <= 9999)
  225.       sprintf( &output[ column ], "%ldK", l / 1000);
  226.    else
  227.       sprintf( &output[ column ], "%ldM", l / 1000000);
  228.    return &output[column];
  229.  
  230. } /* format */
  231.  
  232. static char *status( hostatus current_status )
  233. {
  234.    switch ( current_status )
  235.    {
  236.       default:
  237.        return "??????";
  238.  
  239.       case  phantom:          /* Entry not fully initialized      */
  240.             return "noinit";
  241.  
  242.       case  localhost:        /* This entry is for ourselves      */
  243.             return "local";
  244.  
  245.       case  gatewayed:        /* This entry is delivered to via   */
  246.                               /* an external program on local sys */
  247.             return "gatway";
  248.  
  249.       case  nocall:           /* real host: never called          */
  250.          return "NEVER";
  251.  
  252.       case autodial:          /* Calling now                      */
  253.          return "DIALNG";
  254.  
  255.       case nodevice:          /* Device open failed               */
  256.          return "NODEV";
  257.  
  258.       case startup_failed:
  259.          return "NSTART";
  260.  
  261.       case  inprogress:       /* Call now active                  */
  262.          return "INPROG";
  263.  
  264.       case invalid_device:    /* Bad systems file entry           */
  265.          return "INVDEV";
  266.  
  267.       case  callback_req:     /* System must call us back         */
  268.           return "CALLBK";
  269.  
  270.       case  dial_script_failed:
  271.                               /* Hardcoded auto-dial failed       */
  272.          return "NDIALS";
  273.  
  274.       case  dial_failed:      /* Hardcoded auto-dial failed       */
  275.          return "NODIAL";
  276.  
  277.       case  script_failed:    /* script in L.SYS failed           */
  278.          return "NSCRPT";
  279.  
  280.       case  max_retry:        /* Have given up calling this sys   */
  281.          return "MAXTRY";
  282.  
  283.       case  too_soon:         /* In retry mode: too soon to call  */
  284.          return "TOSOON";
  285.  
  286.       case  succeeded:        /* self-explanatory                 */
  287.       case  called:           /* self-explanatory                 */
  288.          return "SUCESS";
  289.  
  290.       case  wrong_host:       /* Call out failed: wrong system    */
  291.          return "WRGHST";
  292.  
  293.       case  unknown_host:     /* Call in cailed: unknown system   */
  294.          return "UNKNWN";
  295.  
  296.       case  wrong_time:       /* Unable to call because of time   */
  297.          return "WRGTIM";
  298.  
  299.       case  call_failed:      /* Connection dropped in mid-call   */
  300.          return "FAILED";
  301.    } /* switch */
  302.  
  303. } /* status */
  304.